<template>
  <section class="live-statistical">
    <div class="box-card">
      <el-row :gutter="20">
        <el-col>
          <div class="box-card-content">
            <span>直播访问总人次</span>
            <span class="din-front">{{ topInfo.total||'0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>直播总时长</span>
            <span class="din-front">{{ topInfo.duration||'0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>直播最大并发人数</span>
            <span class="din-front">{{ topInfo.maxNum||'0' }}</span>
          </div>
        </el-col>
        <el-col>
          <div class="box-card-content">
            <span>直播最大并发时间</span>
            <span class="din-front">{{ (topInfo.maxTime&& topInfo.maxTime.substring(0,16))||'0' }}</span>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-collapse-transition>
      <div class="course-search separate">
        <div class="course-search-inner">
          <el-row>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">用户名称</div>
                <el-input
                  v-model.trim="listQuery.userRealname"
                  style="width: 80%"
                  class="filter-item"
                  placeholder="请输入用户名称"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">用户手机号</div>
                <el-input
                  v-model.trim="listQuery.phoneNumber"
                  style="width: 80%"
                  class="filter-item"
                  placeholder="请输入用户手机号"
                />
              </div>
            </el-col>
            <!--            <el-col :span="8">-->
            <!--              <div class="search-inner-item">-->
            <!--                <div class="item-label">观看类型</div>-->
            <!--                <el-select v-model="listQuery.visitType" placeholder="请选择" style="width:100%;">-->
            <!--                  <el-option label="直播" value="0" />-->
            <!--                  <el-option label="回放" value="1" />-->
            <!--                </el-select>-->
            <!--              </div>-->
            <!--            </el-col>-->

          </el-row>
        </div>
        <div class="course-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="handleReset">重置</el-button>
        </div>
      </div>
    </el-collapse-transition>
    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>直播统计</span>
      </section>
      <section class="main-buttons-btns">
        <el-button style="margin-left: 10px" @click="handleExport">导出</el-button>
        <el-button style="margin-left: 10px" type="primary" @click="backFun">返回</el-button>
      </section>
    </section>
    <div class="classify-tab">
      <el-tabs v-model="listQuery.visitType" @tab-click="handleTabClick">
        <el-tab-pane v-for="(item,i) in types" :key="i" :label="item.name" :name="item.id" />
      </el-tabs>
    </div>
    <section class="main-table">
      <v-table
        :list="list"
        tag="liveStatistics"
        :selection="false"
        :hover-arr="['balance']"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
      />
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </section>
  </section>
</template>
<script>
import {
  queryRecord, getTopInfo, exportFileDetailMask, exportFileDetailNoMask
} from '../../api/tj'
import { exportSign } from '@/utils/fileImportOrExportSign'
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import elDragDialog from '@/directive/el-drag-dialog'
import CryptoJS from '@/utils/aesJiaJM'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
export default {
  name: 'LiveStatistical',
  components: {
    VTable,
    Pagination
  },
  directives: {
    elDragDialog
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        userRealname: '',
        phoneNumber: '',
        visitType: '-1'
      },
      list: [],
      total: 0,
      listLoading: false,
      topInfo: {},
      backUrl: '',
      orderType: '0',
      types: [
        {
          id: '-1',
          name: '全部'
        },
        {
          id: '0',
          name: '直播'
        },
        {
          id: '1',
          name: '回放'
        },
        {
          id: '2',
          name: '预约'
        }
      ]
    }
  },
  created() {
    if (this.$route.query) {
      this.getList()
      this.getInfo()
    } else {
      this.$message.error('页面参数错误')
      this.$router.back()
    }
  },
  methods: {
    /**
     * 选项卡切换
     */
    handleTabClick() {
      this.listQuery.page = 1
      this.getList()
    },
    backFun() {
      this.$router.back()
    },
    /**
     * 导出
     */
    handleExport() {
      const req = {
        liveActivityId: this.$route.query.id || '',
        ccRoomId: this.$route.query.ri || '',
        userRealname: this.listQuery.userRealname ? this.listQuery.userRealname : '',
        phoneNumber: this.listQuery.phoneNumber ? this.listQuery.phoneNumber : '',
        visitType: this.listQuery.visitType ? this.listQuery.visitType : ''
      }
      const query = exportSign(req).obj
      exportCheck('ACTIVITY_CENTER_LIVE_EVENT', this.$route.query.id, exportFileDetailMask, exportFileDetailNoMask, query, '观看人员.xlsx')
    },
    filtercolumn(scope, item) {
      if (item === 'userIdnumber' || item === 'phoneNumber') {
        return CryptoJS.$aesJieM(scope.row[item])
      } else {
        return scope.row[item]
      }
    },
    handleReset() {
      this.listQuery.page = 1
      this.listQuery.userRealname = ''
      this.listQuery.phoneNumber = ''
      this.listQuery.visitType = '-1'
      this.getList()
      this.getInfo()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
      this.getInfo()
    },
    getInfo() {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      const query = {
        id: this.$route.query.id,
        roomId: this.$route.query.ri
      }
      return new Promise((resolve, reject) => {
        getTopInfo(query).then(res => {
          loading.close()
          if (res.data.code === '200') {
            this.topInfo = res.data.data
          } else {
            this.$message.error(res.data.msg || '获取详情失败')
          }
        }).catch(error => {
          loading.close()
          reject(error)
        })
      })
    },
    getList(obj) {
      this.listLoading = true
      const query = {
        page: this.listQuery.page,
        pageSize: this.listQuery.limit,
        liveActivityId: this.$route.query.id,
        ccRoomId: this.$route.query.ri,
        userRealname: this.listQuery.userRealname ? this.listQuery.userRealname : '',
        phoneNumber: this.listQuery.phoneNumber ? this.listQuery.phoneNumber : '',
        visitType: this.listQuery.visitType ? this.listQuery.visitType : ''
      }
      return new Promise((resolve, reject) => {
        queryRecord(query).then(response => {
          this.list = response.data.data.rows || []
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }
  }
}
</script>
<style lang="scss">
	@import '@/styles/mixin.scss';
	$dark_gray: #bfced6;

	.live-statistical {
		padding: 10px;

		.el-dialog .el-dialog__body {
			max-height: 73vh !important;
		}

		.line {
			text-align: center;
		}

    .box-card {
      margin-bottom: 10px;
      text-align: center;
      background-color: #fff;
      padding: 20px;
      .el-col{
        width: 25% !important;
        .box-card-content{
          display: flex;
          flex-direction: column;
          justify-content: center;
          font-size: 16px;
          color: #666;
          border-radius: 8px;
          padding: 14px 0;
          span:last-child {
            margin-top: 10px;
            font-size: 24px;
            font-weight: bold;
            line-height: 1;
          }
        }
        &:first-child .box-card-content{
          background: #fff2f1;
          span:last-child{
            color: #E44D42;
          }
        }
        &:nth-child(2) .box-card-content{
          background: #F3FAFF;
          span:last-child{
            color: #3EAAF9;
          }
        }
        &:nth-child(3) .box-card-content{
          background: #FFF8F1;
          span:last-child{
            color: #F08628;
          }
        }
        &:nth-child(4) .box-card-content{
          background: #F4FFE7;
          span:last-child{
            color: #82BC3C;
          }
        }
        &:nth-child(5) .box-card-content{
          background: #F8F5FF;
          span:last-child{
            color: #966AF9;
          }
        }
      }
      .current-position-name {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 10px;
      }
    }

		.course-search {
			background-color: #fff;
			padding: 0 10px;

			.svg-container {
				padding: 0 5px 0 10px;
				color: $dark_gray;
				vertical-align: middle;
				display: inline-block;

				&_login {
					font-size: 20px;
				}
			}

			.search-input {
				width: 60%;
				position: relative;

				&:after {
					content: "";
					position: absolute;
					left: -25px;
					right: 0;
					bottom: 8px;
					height: 1px;
					background: rgba(226, 227, 232, 1);
				}

				input {
					outline: none;
					background: transparent;
					border: none;
					outline: medium;
					padding: 0;

					&:focus {
						outline: none;
						background-color: transparent;
					}
				}
			}

			.course-search-btn {
				display: inline-block;
				float: right;

				.el-button.is-round {
					padding: 10px 30px;
					margin-right: 34px;
				}

				.course-search-more {
					font-size: 14px;
					font-weight: 500;
					@include font-color($mainColor);
					cursor: pointer;
					margin-left: 10px;
				}
			}

			&.merge {
				height: 50px;
				line-height: 50px;
			}

			&.separate {
				.course-search-inner {
					padding-top: 10px;

					// .el-input--medium .el-input__inner {
					// 	padding-left: 30px !important;
					// }
					.search-inner-item {
						.item-label {
							height: 30px;
							line-height: 30px;
							font-size: 14px;
							color: #a6a6a6;
							font-weight: 400;
						}

						.el-input {
							position: relative;

							.el-input__inner {
								border: none;
								padding: 0;
							}

							&:after {
								content: "";
								height: 1px;
								background-color: #e2e3e8;
								position: absolute;
								left: 0;
								right: 0;
								bottom: 0;
							}
						}
					}
				}

				.course-search-btn {
					text-align: center;
					display: block;
					float: none;
					height: 56px;
					line-height: 56px;
				}
			}
		}

		.main-buttons {
			display: flex;
			line-height: 36px;
			margin: 10px 0;

			.main-buttons-title {
				flex: 1;
				height: 36px;
				line-height: 36px;
				font-size: 16px;
				font-weight: bold;
				color: rgba(51, 51, 51, 1);

				.num {
					@include font-color($mainColor);
				}
			}
		}
    .classify-tab {
      width: 100%;
      margin-bottom: 10px;
      padding: 0 10px;
      background-color: #fff;
      display: flex;
      border-radius: 4px;

      .el-tabs__nav-wrap::after {
        display: none;
      }

      .el-tabs__header {
        margin: 0;
      }
    }
	}
</style>
